package com.example.month11.festivalsms;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.example.month11.festivalsms.fragment.FestivalCategoryFragment;
import com.example.month11.festivalsms.fragment.SmsHistoryFragment;
import com.example.recyclerview01.R;
import com.google.android.material.tabs.TabLayout;

/**
 * 节日短信,主界面
 */
public class FestivalSmsActivity extends AppCompatActivity {
    private String[] mTitles = new String[]{"节日短信", "发送记录"};
    TabLayout mTabLayout;
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_festival_sms);
        initViews();
    }

    private void initViews() {
        mTabLayout = findViewById(R.id.id_tablayout);
        mViewPager = findViewById(R.id.id_viewpager);

        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                if (position==0) {
                    return new FestivalCategoryFragment();
                }
                return new SmsHistoryFragment();
            }

            @Override
            public int getCount() {
                return mTitles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitles[position];
            }
        });
        mTabLayout.setupWithViewPager(mViewPager);
    }

}